package spring.my.db.sharding.demo.response;

import spring.my.db.sharding.demo.exception.BzException;

public class CommonPageResponse<T> extends Response {
    private static final long serialVersionUID = -7422565331571245089L;
    private Page<T> page;

    public Page<T> getPage() {
        return page;
    }

    public void setPage(Page<T> page) {
        this.page = page;
    }

    public CommonPageResponse() {
        super();
    }

    public CommonPageResponse(int status, String message) {
        super(status, message);
    }


    public static <T> CommonPageResponse<T> getInstance() {
        return new CommonPageResponse<>();
    }

    public static <T> CommonPageResponse<T> getInstance(BzException ex) {
        if (ex != null) {
            return getInstance(ex.getCode(), ex.getMessage());
        }
        return getInstance();
    }

    public static <T> CommonPageResponse<T> getInstance(int code, String mesage) {
        CommonPageResponse<T> commonResponse = new CommonPageResponse<T>();
        commonResponse.setStatus(code);
        commonResponse.setMessage(mesage);
        return commonResponse;
    }


    public static <T> CommonPageResponse<T> getInstance(Page<T> t) {
        CommonPageResponse<T> commonResponse = new CommonPageResponse<T>();
        commonResponse.setStatus(ResponseCode.SUCCESS.getCode());
        commonResponse.setPage(t);
        return commonResponse;
    }

    public CommonPageResponse status(int code) {
        this.setStatus(code);
        return this;
    }

    public CommonPageResponse message(String message) {
        this.setMessage(message);
        return this;
    }

}
